package com.gnote.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/client")
@RequiredArgsConstructor
public class TestController {
    private final ChatClient.Builder chatClientBuild;
    private final ChatMemory chatMemory;

    @GetMapping(value = "/test", produces = "text/stream;charset=UTF-8")
    public Flux<String> test(String msg) {
        ChatClient chatClient = chatClientBuild.defaultAdvisors(
                PromptChatMemoryAdvisor.builder(chatMemory).build()
        ).build();
        return chatClient.prompt()
                .user(msg)
                .stream()
                .content();

    }




}
